package org.emet.entity.storage;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.emet.jee.console.entity.BaseEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 进货记录
 * 
 * @author alex
 * 
 */
@Entity
@Table(name = "T_PURCHASE_HIST")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class PurchaseHist extends BaseEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String flowNo;
	private String operatorSN;
	private String operatorName;
	private Vender vender;
	private List<PurchaseItem> items;
	private Date date = new Date(new Date().getTime());

	public String getFlowNo() {
		return flowNo;
	}

	public void setFlowNo(String flowNo) {
		this.flowNo = flowNo;
	}

	public String getOperatorSN() {
		return operatorSN;
	}

	public void setOperatorSN(String operatorSN) {
		this.operatorSN = operatorSN;
	}

	public String getOperatorName() {
		return operatorName;
	}

	public void setOperatorName(String operatorName) {
		this.operatorName = operatorName;
	}

	@ManyToOne
	@JoinColumn(name = "vender_id")
	public Vender getVender() {
		return vender;
	}

	public void setVender(Vender vender) {
		this.vender = vender;
	}

	@OneToMany(mappedBy = "buyHistory", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@Fetch(FetchMode.SUBSELECT)
	public List<PurchaseItem> getItems() {
		return items;
	}

	public void setItems(List<PurchaseItem> items) {
		this.items = items;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
	
}
